using UnityEditor;
using UnityEngine;
using UnityX;

namespace UnityXEditor
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(FollowControl), true)]
    internal class FollowControlEditor : Editor
    {
        private SerializedProperty m_Target;
        private SerializedProperty m_TargetPosition;
        private SerializedProperty m_TargetPositionSmoothTime;

        private SerializedProperty m_AngleX;
        private SerializedProperty m_AngleXMin;
        private SerializedProperty m_AngleXMax;
        private SerializedProperty m_AngleXSmoothTime;

        private SerializedProperty m_AngleY;
        //private SerializedProperty m_AngleYMin;
        //private SerializedProperty m_AngleYMax;
        private SerializedProperty m_AngleYSmoothTime;
        //private SerializedProperty m_AngleFollow;

        private SerializedProperty m_Distance;
        private SerializedProperty m_DistanceMin;
        private SerializedProperty m_DistanceMax;
        private SerializedProperty m_DistanceSmoothTime;

        private SerializedProperty m_KeyboardControl;
        private SerializedProperty m_KeyboardControlAngleXSpeed;
        private SerializedProperty m_KeyboardControlAngleYSpeed;
        private SerializedProperty m_KeyboardControlDistanceSpeed;
        private SerializedProperty m_UpKey;
        private SerializedProperty m_DownKey;
        private SerializedProperty m_LeftKey;
        private SerializedProperty m_RightKey;
        private SerializedProperty m_FrontKey;
        private SerializedProperty m_BackKey;

        private SerializedProperty m_MouseControl;
        private SerializedProperty m_MouseKey;
        private SerializedProperty m_MouseControlAngleXSpeed;
        private SerializedProperty m_MouseControlAngleYSpeed;
        private SerializedProperty m_MouseControlDistanceSpeed;

        private SerializedProperty m_TouchControl;
        private SerializedProperty m_TouchControlAngleXSpeed;
        private SerializedProperty m_TouchControlAngleYSpeed;
        private SerializedProperty m_TouchControlDistanceSpeed;

        private SerializedProperty m_ScreenArea;
        private SerializedProperty m_UIClickCheck;
        private SerializedProperty m_DistanceSpeedChangeRatio;

        private SerializedProperty m_OccludeCheck;

        protected void OnEnable()
        {
            m_Target = serializedObject.FindProperty("m_Target");
            m_TargetPosition = serializedObject.FindProperty("m_TargetPosition");
            m_TargetPositionSmoothTime = serializedObject.FindProperty("m_TargetPositionSmoothTime");

            m_AngleX = serializedObject.FindProperty("m_AngleX");
            m_AngleXMin = serializedObject.FindProperty("m_AngleXMin");
            m_AngleXMax = serializedObject.FindProperty("m_AngleXMax");
            m_AngleXSmoothTime = serializedObject.FindProperty("m_AngleXSmoothTime");

            m_AngleY = serializedObject.FindProperty("m_AngleY");
            //m_AngleYMin = serializedObject.FindProperty("m_AngleYMin");
            //m_AngleYMax = serializedObject.FindProperty("m_AngleYMax");
            m_AngleYSmoothTime = serializedObject.FindProperty("m_AngleYSmoothTime");
            //m_AngleFollow = serializedObject.FindProperty("m_AngleFollow");

            m_Distance = serializedObject.FindProperty("m_Distance");
            m_DistanceMin = serializedObject.FindProperty("m_DistanceMin");
            m_DistanceMax = serializedObject.FindProperty("m_DistanceMax");
            m_DistanceSmoothTime = serializedObject.FindProperty("m_DistanceSmoothTime");

            m_KeyboardControl = serializedObject.FindProperty("m_KeyboardControl");
            m_KeyboardControlAngleXSpeed = serializedObject.FindProperty("m_KeyboardControlAngleXSpeed");
            m_KeyboardControlAngleYSpeed = serializedObject.FindProperty("m_KeyboardControlAngleYSpeed");
            m_KeyboardControlDistanceSpeed = serializedObject.FindProperty("m_KeyboardControlDistanceSpeed");
            m_UpKey = serializedObject.FindProperty("m_UpKey");
            m_DownKey = serializedObject.FindProperty("m_DownKey");
            m_LeftKey = serializedObject.FindProperty("m_LeftKey");
            m_RightKey = serializedObject.FindProperty("m_RightKey");
            m_FrontKey = serializedObject.FindProperty("m_FrontKey");
            m_BackKey = serializedObject.FindProperty("m_BackKey");

            m_MouseControl = serializedObject.FindProperty("m_MouseControl");
            m_MouseKey = serializedObject.FindProperty("m_MouseKey");
            m_MouseControlAngleXSpeed = serializedObject.FindProperty("m_MouseControlAngleXSpeed");
            m_MouseControlAngleYSpeed = serializedObject.FindProperty("m_MouseControlAngleYSpeed");
            m_MouseControlDistanceSpeed = serializedObject.FindProperty("m_MouseControlDistanceSpeed");

            m_TouchControl = serializedObject.FindProperty("m_TouchControl");
            m_TouchControlAngleXSpeed = serializedObject.FindProperty("m_TouchControlAngleXSpeed");
            m_TouchControlAngleYSpeed = serializedObject.FindProperty("m_TouchControlAngleYSpeed");
            m_TouchControlDistanceSpeed = serializedObject.FindProperty("m_TouchControlDistanceSpeed");

            m_ScreenArea = serializedObject.FindProperty("m_ScreenArea");
            m_UIClickCheck = serializedObject.FindProperty("m_UIClickCheck");
            m_DistanceSpeedChangeRatio = serializedObject.FindProperty("m_DistanceSpeedChangeRatio");

            m_OccludeCheck = serializedObject.FindProperty("m_OccludeCheck");
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_Target, new GUIContent("目标对象"));
            Transform tt = m_Target.objectReferenceValue as Transform;
            if (tt == null)
            {
                EditorGUILayout.PropertyField(m_TargetPosition, new GUIContent("目标位置"));
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                if (!EditorApplication.isPlaying)
                {
                    m_TargetPosition.vector3Value = tt.position;
                }
                EditorGUILayout.PropertyField(m_TargetPosition, new GUIContent("目标位置"));
                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.PropertyField(m_AngleX, new GUIContent("俯仰角度"));
            EditorGUILayout.PropertyField(m_AngleY, new GUIContent("左右角度"));
            EditorGUILayout.PropertyField(m_Distance, new GUIContent("目标距离"));

            //限制limit
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_AngleXMin, new GUIContent("俯仰角度最小"));
            EditorGUILayout.PropertyField(m_AngleXMax, new GUIContent("俯仰角度最大"));
            //EditorGUILayout.PropertyField(m_AngleYMin, new GUIContent("左右角度最小"));
            //EditorGUILayout.PropertyField(m_AngleYMax, new GUIContent("左右角度最大"));
            EditorGUILayout.PropertyField(m_DistanceMin, new GUIContent("目标距离最小"));
            EditorGUILayout.PropertyField(m_DistanceMax, new GUIContent("目标距离最大"));

            //平滑smooth
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_TargetPositionSmoothTime, new GUIContent("目标位置平滑时间"));
            EditorGUILayout.PropertyField(m_AngleXSmoothTime, new GUIContent("俯仰角度平滑时间"));
            EditorGUILayout.PropertyField(m_AngleYSmoothTime, new GUIContent("左右角度平滑时间"));
            EditorGUILayout.PropertyField(m_DistanceSmoothTime, new GUIContent("目标距离平滑时间"));

            //控制
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_KeyboardControl, new GUIContent("键盘控制"));
            if (m_KeyboardControl.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_KeyboardControlAngleXSpeed, new GUIContent("键盘控制俯仰角度速度"));
                EditorGUILayout.PropertyField(m_KeyboardControlAngleYSpeed, new GUIContent("键盘控制左右角度速度"));
                EditorGUILayout.PropertyField(m_KeyboardControlDistanceSpeed, new GUIContent("键盘控制距离速度"));
                EditorGUILayout.PropertyField(m_UpKey, new GUIContent("上旋键"));
                EditorGUILayout.PropertyField(m_DownKey, new GUIContent("下旋键"));
                EditorGUILayout.PropertyField(m_LeftKey, new GUIContent("左旋键"));
                EditorGUILayout.PropertyField(m_RightKey, new GUIContent("右旋键"));
                EditorGUILayout.PropertyField(m_FrontKey, new GUIContent("拉近建"));
                EditorGUILayout.PropertyField(m_BackKey, new GUIContent("拉远建"));
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.PropertyField(m_MouseControl, new GUIContent("鼠标控制"));
            if (m_MouseControl.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_MouseKey, new GUIContent("鼠标按键"));
                EditorGUILayout.PropertyField(m_MouseControlAngleXSpeed, new GUIContent("鼠标控制俯仰角度速度"));
                EditorGUILayout.PropertyField(m_MouseControlAngleYSpeed, new GUIContent("鼠标控制左右角度速度"));
                EditorGUILayout.PropertyField(m_MouseControlDistanceSpeed, new GUIContent("鼠标滚轮控制距离速度"));
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.PropertyField(m_TouchControl, new GUIContent("触摸控制"));
            if (m_TouchControl.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_TouchControlAngleXSpeed, new GUIContent("触摸控制俯仰角度速度"));
                EditorGUILayout.PropertyField(m_TouchControlAngleYSpeed, new GUIContent("触摸控制左右角度速度"));
                EditorGUILayout.PropertyField(m_TouchControlDistanceSpeed, new GUIContent("触摸控制距离速度"));
                EditorGUI.indentLevel--;
            }
            if (m_MouseControl.boolValue || m_TouchControl.boolValue)
            {
                EditorGUILayout.PropertyField(m_ScreenArea, new GUIContent("屏幕可控区域"));
                EditorGUILayout.PropertyField(m_UIClickCheck, new GUIContent("点击到UI上检测"));
            }

            if (m_KeyboardControl.boolValue || m_MouseControl.boolValue || m_TouchControl.boolValue)
            {
                EditorGUILayout.PropertyField(m_DistanceSpeedChangeRatio, new GUIContent("距离控制拉近减速比"));
            }

            EditorGUILayout.Space();
            //EditorGUILayout.PropertyField(m_AngleFollow, new GUIContent("是否跟着目标转动"));
            EditorGUILayout.PropertyField(m_OccludeCheck, new GUIContent("前面被遮挡检测"));

            serializedObject.ApplyModifiedProperties();
        }
    }
}